package com.quickdemo.api;

import com.quickdemo.pojo.dto.IdVersion;
import com.quickdemo.pojo.dto.UserDTO;
import com.quickdemo.pojo.dto.UserPageQueryDTO;
import com.quickdemo.result.PageResult;
import com.quickdemo.result.Result;
import io.swagger.annotations.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
 * @author ckj
 */
@CrossOrigin
@Api(tags = "用户管理", value = "/quick/demo/v1")
@RequestMapping("/quick/demo/v1")
@Validated
public interface UserApi {

    /**
     * 添加用户
     * @author ckj
     * @return com.quickdemo.result.Result<java.lang.Boolean>
     */
    @ApiOperation( value = "增加用户",notes="界面增加用户")
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功"),
            @ApiResponse(code=-1,message = "请求执行没有成功但是发生异常")
    }
    )
    @PostMapping("/user")
    Result<Boolean> add(@NotNull @Valid @RequestBody @ApiParam(value = "用户数据", required = true) UserDTO userDTO);

    /**
     *  删除用户
     * @param id  记录id
     * @return  true 成功 false失败
     */
    @ApiOperation(value = "删除用户通过id",notes = "通过id删除用户")
    @ApiImplicitParam(name = "id",required =true,dataType = "Long",paramType = "path")
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功"),
            @ApiResponse(code=-1,message = "没有更新记录,非0码则代表失败")
    }
    )
    @DeleteMapping("/user/{id}")
    Result<Boolean> remove(@PathVariable @NotNull Long id);

    /**
     * 批量删除用户
     * 批量删除用户
     */
    @ApiOperation(value = "批量删除用户通过id和版本",response = Boolean.class,notes = "notes说明")
    @ApiImplicitParams({@ApiImplicitParam(name = "idVersions",required =true,dataType = "IdVersion",paramType = "body")}
    )
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功"),
            @ApiResponse(code=-1,message = "没有更新记录,非0码则代表失败")
    }
    )
    @DeleteMapping("/batch/user")
    Result<Boolean> remove(@NotEmpty @RequestBody  IdVersion[] idVersions);

    /**
     * 界面调用接口更新用户信息
     * @param userDTO 用户信息包含 id
     * @return true成功 false失败
     */
    @ApiOperation( value = "更新用户信息",notes = "修改界面保存调用该方法")
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功"),
            @ApiResponse(code=-1,message = "没有更新记录,非0码则代表失败")
    }
    )
    @PutMapping("/user")
    Result<Boolean> update(@NotNull @Valid @RequestBody  @ApiParam UserDTO userDTO);

    /**
     * 界面调用接口更新用户信息
     * @param UserPageQueryDTO 用户信息包含 id
     * @return true成功 false失败
     */
    @ApiOperation(value = "查询用户列表接口",notes = "支持模糊查询")
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功"),
            @ApiResponse(code=-1,message = "没有更新记录,非0码则代表失败")
    })
    @GetMapping("/user")
    Result<PageResult> search(@NotNull @Valid UserPageQueryDTO UserPageQueryDTO);

    /**
     *  页面编辑行的时候传id从后端加载数据
     * @param id  当前行id
     * @return  用户数据
     */
    @ApiOperation(value = "根据id获取用户接口",notes = "用于编辑和查看的时候获取用户")
    @ApiImplicitParam(name = "id",value = "主键值",required = true,dataType = "Long",paramType = "path")
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功,非0码则代表失败"),
    })
    @GetMapping("/user/{id}")
    Result<UserDTO> findById( @PathVariable @NotNull Long id);
}
